﻿using System.Runtime.Serialization;
using System.Windows.Media;
using Foundation;
using Poet.Modules;

namespace Poet.ViewModels
{
    /// <summary>
    /// PaletteViewModel.
    /// </summary>
    [DataContract]
    internal class PaletteSetViewModel : DocumentSettingsViewModel<PaletteSet>
    {
        public PaletteSetViewModel()
        {
            Initialize();
        }

        protected override sealed PaletteSet GetFactorySettings()
        {
            return
                new PaletteSet
                    {
                        Name = "Factory",
                        Foreground = Brushes.Black,
                        Background = Brushes.White,
                        SelectedText = null,
                        SelectionBorder =
                            new Pen {Brush = new SolidColorBrush(Colors.BlueViolet) {Opacity = 0.5}, Thickness = 0.5},
                        SelectionBrush = new SolidColorBrush(Colors.BlueViolet) {Opacity = 0.2},
                        CurrentLineBackground = new SolidColorBrush(Colors.LightSkyBlue) {Opacity = 0.1},
                        CurrentLineBorder =
                            new Pen {Brush = new SolidColorBrush(Colors.SkyBlue) {Opacity = 0.7}, Thickness = 0.5},
                        AccentuateBackground = new SolidColorBrush(Colors.Yellow) {Opacity = 0.7},
                        AccentuateBorder = new Pen {Brush = new SolidColorBrush(Colors.Gold) {Opacity = 0.7}},
                        LineNumberForeground = Brushes.Gray,
                        LineNumberSeparator = Brushes.Gray,

                        AccentuateBorderCornerRadius = 0,
                        CurrentLineBorderCornerRadius = 0,
                        SelectionBorderCornerRadius = 2,
                    };
        }

        [OnDeserialized]
        private void Initialize(StreamingContext context = default(StreamingContext))
        {
            ApplicationClosing += () => this.TrySerializeDataContract();
            GetSettingsAction += model => model.TextEditorViewModel.GetPalette();
            SetSettingsAction += (model, appearance) => model.TextEditorViewModel.SetPalette(appearance);
        }
    }
}
